package 耿翔宇;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;

import cn.hutool.core.io.FileUtil;

public class CallName02 {

	public static void main(String[] args) {
		int i = 1;
		while(i<=20){
			callName();
			i++;
		}
	}

	public static void callName(){
		List<String> girlsName = FileUtil.readLines(new File("girls.txt"), "utf-8");
		List<String> boysName = FileUtil.readLines(new File("boys.txt"), "utf-8");
		List<String> callName = new ArrayList<String>();
		int ran = new Random().nextInt(100);
		if(ran<=69){
			callOne(boysName,callName);
		}else{
			callOne(girlsName,callName);
		}
		List<String> calledNames = FileUtil.readLines(new File("randomcall02.txt"), "utf-8");
		Map<String, Long> calledTimes = calledNames.stream().filter(s->!s.equals("")).collect(Collectors.groupingBy(c->c.split("-")[1],Collectors.counting()));
		long tb = calledTimes.containsKey("��")?calledTimes.get("��"):0;
		long tg = calledTimes.containsKey("Ů")?calledTimes.get("Ů"):0;
		System.out.printf(" | �� ��Ů = %d : %d\n",tb,tg);
	}
	public static void callOne(List<String> name,List<String> called){
		Collections.shuffle(name);
		String n = name.get(0);
		called.add(n.substring(0,n.length()-3));
		FileUtil.writeLines(called, new File("randomcall02.txt"), "utf-8",true);
		System.out.print(n.substring(0,n.length()-3));
	}
}
